<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../static/component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="" id="group-add">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label lang="zh" class="layui-form-label">项目名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="{{.Name}}"
                           lay-verify="required"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <input type="hidden" name="project_id" value="{{.ID}}">
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" id="group-submit-button" lay-submit=""
                    lay-filter="group-save">
                <i lang="zh" class="layui-icon layui-icon-ok">提交</i>

            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i lang="zh" class="layui-icon layui-icon-refresh">重置</i>
            </button>
        </div>
    </div>
</form>
<script src="../../../static/component/layui/layui.js"></script>
<script src="../../../static/component/pear/pear.js"></script>
<script>
    layui.use(['lang','form', 'jquery', 'sail'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let sail = layui.sail;
        let lang = layui.lang;
        const accessToken = localStorage.getItem("accessToken");
        sail.prefilterAjax();
        $(function(){
            form.render();
        });
        form.on('submit(group-save)', function (data) {
            $('#group-submit-button').attr('disabled', 'true');
            $.ajax({
                url: '/sail/v1/project/edit',
                data: JSON.stringify({
                    name: data.field.name,
                    project_id: parseInt(data.field.project_id),
                }),
                contentType: "application/json;charset=utf-8",
                headers: sail.setAuth(accessToken),
                dataType: 'json',
                cache: false,
                type: 'post',
                success: function (result) {
                    sail.checkSuccess(result, function (resp) {
                        layer.msg(lang.translate("成功"), {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    })
                },
                error: sail.ajaxError,
                complete: function () {
                    setTimeout(function () {
                        $('#group-submit-button').removeAttr('disabled');
                    }, 2000);
                }
            })
            return false;
        });
    })
</script>
</body>
</html>